import requests
from ui_publish import Ui_Publish
from login import LoginWindow
from PyQt5.QtWidgets import QDialog


class PublishWindow(QDialog, Ui_Publish):
    def __init__(self, username, parent=None):
        super(PublishWindow, self).__init__(parent=parent)
        self.username = username
        print(self.username)
        self.setupUi(self)
        self.publishButton.clicked.connect(self.publish)

    def publish(self):
        resp = requests.post("http://127.0.0.1:8888/goods", data={
            "ower": self.username,
            "name": self.nameLine.text(),
            "type": self.typeComboBox.currentText(),
            "describe": self.descriText.toPlainText(),

        })
        if resp.json()["ok"] == True:
            self.close()
        print(resp.json())
